<?php


namespace App\Common\Comp;


use App\Model\ImMessageCallBack;
use App\Service\CheckContentLogService;
use Illuminate\Support\Facades\Log;

class CheckComp
{
    protected $resDate;
    public function __construct()
    {
        //初始化返回值
        $this->resDate = ['code' => 200, 'msg' => '', 'data' => []];
    }
    /**
     * 查询媒体审核作业详情
     * @param $redisData
     * @return array
     */
    public function imVideoResult($result)
    {
        $antispam = $result['antispam'];
        $suggestion = $antispam['suggestion'];//0通过，大于0不通过
        $taskId = $antispam['taskId'];//第三方审核任务唯一ID
        $videoId = $dataId = $antispam['dataId'];

        (new CheckContentLogService())->updateCheckContentLog($taskId, 'imVideoResult');
        if ($antispam['status'] == 2) {
            //$suggestion 0通过，大于0不通过
            if ($suggestion == 0) {
                //通过
            } else {
                //不通过 触发撤回消息
                $msgInfo = ImMessageCallBack::query()->where("id", $dataId)->first();

                if (!empty($msgInfo)) {
                    $msgInfo = $msgInfo->toArray();
                    if ($msgInfo['type'] == 1) {
                        $res = (new ImComp())->adminMsgwithdraw($msgInfo['msg_key'], $msgInfo['from_account'], $msgInfo['to_account']);
                    } elseif ($msgInfo['type'] == 2) {
                        $res = (new ImComp())->groupMsgRecall($msgInfo['group_id'], [["MsgSeq" => $msgInfo['msg_key']]]);
                    }
                } else {
                    Log::error("===========================================视频信息审核不通过触发:" . $dataId);
                }
            }
            return $this->resDate;
        } else {
            //检测失败
            $this->resDate['code'] = 50004;
            $this->resDate['msg'] = "视频审核中";
            return $this->resDate;
        }
    }
}
